package com.zhuss.controller.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhuss.bean.bo.order.order.CancelOrderBo;
import com.zhuss.bean.bo.order.order.CareOrderBo;
import com.zhuss.bean.bo.order.order.CareOrderRefundBo;
import com.zhuss.bean.bo.order.order.ConfirmTakeBo;
import com.zhuss.bean.bo.order.order.CreateOrderBo;
import com.zhuss.bean.bo.order.order.CreatePayOrderRefundBo;
import com.zhuss.bean.bo.order.order.DetailOrderBo;
import com.zhuss.bean.bo.order.order.PayOrderBo;
import com.zhuss.bean.bo.order.order.app.DetailTicketBo;
import com.zhuss.bean.bo.order.order.app.ListOrderBo;
import com.zhuss.bean.bo.order.order.app.ListTicketBo;
import com.zhuss.bean.vo.order.order.DetailOrderVo;
import com.zhuss.bean.vo.order.order.app.ListOrderVo;
import com.zhuss.bean.vo.order.order.app.ListTicketVo;
import com.zhuss.common.AbstractBo;
import com.zhuss.common.BaseController;
import com.zhuss.common.OrderService;
import com.zhuss.common.PageVo;
import com.zhuss.exception.DzcxException;
import com.zhuss.order.order.OrderOperateServiceExt;


/**
 * @description: 订单操作的Controller
 * @author: zhushanshuo
 * @create: Mon Jan 11 10:24:29 CST 2021
 **/
@RestController
@RequestMapping("/order")
public class OrderOperateController extends BaseController {
	
	@Autowired
	@Qualifier("orderOperateService")
	private OrderService<Object, Object> orderOperateService;
	
	@Autowired
	@Qualifier("orderOperateServiceExt")
	private OrderOperateServiceExt orderOperateServiceExt;
	
	/**
	 * 创建
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
    @PostMapping("/create")
    public Object create(@RequestBody CreateOrderBo bo) throws DzcxException {
		
		Object result = orderOperateService.create(bo);
		return result;
    }
	
	/**
	 * 支付单
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
    @PostMapping("/pay")
    public Object pay(@RequestBody PayOrderBo bo) throws DzcxException {
		
		Object result = orderOperateService.pay(bo);
		return result;
    }
	
	/**
	 * 取消
	 * @param bo
	 * @throws AabException
	 */
	@ResponseBody
    @PostMapping("/cancel")
    public void cancel(@RequestBody CancelOrderBo bo) throws DzcxException {
		
		orderOperateService.cancel(bo);
    }
	
	/**
	 * 根据orderId 查询订单详情
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
    @PostMapping("/careOrderForUpdate")
    public Object careOrderForUpdate(@RequestBody CareOrderBo bo) throws Exception {
		
		Object result = orderOperateService.careOrderForUpdate(bo);
		return result;
    }
	
	/**
	 * 确认上车
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
	@PostMapping("/confirmTake")
	public void	confirmTake(@RequestBody ConfirmTakeBo bo) throws Exception {
		
		orderOperateService.confirmTake(bo);
	}
	
	/**
	 * 详情
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/detailOrderForUpdate")
    public Object detailForUpdate(@RequestBody DetailOrderBo bo) throws DzcxException {
		
		DetailOrderVo result = (DetailOrderVo) orderOperateService.detailForUpdate(bo);
		return result;
    }
	
	/**
	 * 列表
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping("/listOrderForUpdate")
    public Object listOrderForUpdate(@RequestBody ListOrderBo bo) throws DzcxException {
		
		PageVo<ListOrderVo> result = (PageVo<ListOrderVo>) orderOperateService.listOrderForUpdate(bo);
		return result;
    }
	
	/**
	 * 车票
	 * 列表
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping("/listTicketForUpdate")
    public Object listTicketForUpdate(@RequestBody ListTicketBo bo) throws DzcxException {
		
		PageVo<ListTicketVo> result = (PageVo<ListTicketVo>) orderOperateService.listTicketForUpdate(bo);
		return result;
    }
	
	/**
	 * 车票
	 * 列表
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/detailTicket")
	public Object detailTicket(@RequestBody DetailTicketBo bo) throws DzcxException {
		
		Object result = orderOperateService.detailTicket(bo);
		return result;
	}
	
	/**
	 * 退款
	 * 车票
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/refund")
	public Object refund(@RequestBody CreatePayOrderRefundBo bo) throws DzcxException {
		
		Object result = orderOperateService.refund(bo);
		return result;
	}
	
	/**
	 * 根据orderRefundNo 查询退款订单详情
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
	@PostMapping("/careOrderRefundForUpdate")
	public Object careOrderRefundForUpdate(@RequestBody CareOrderRefundBo bo) throws Exception {
		
		Object result = orderOperateService.careOrderRefundForUpdate(bo);
		return result;
	}
	
	/**
	 * 车票
	 * 列表
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/latestTicket")
    public Object latestTicket(@RequestBody AbstractBo bo) throws DzcxException {
		
		ListTicketVo result = (ListTicketVo) orderOperateService.latestTicket(bo);
		return result;
    }
	
	/**
	 * 我的车票 所有车票
	 * 列表
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping("/listTicket")
    public Object listTicket(@RequestBody ListTicketBo bo) throws DzcxException {
		
		PageVo<ListTicketVo> result = (PageVo<ListTicketVo>) orderOperateService.listTicket(bo);
		return result;
    }
	
}
